package A1_数组;

public class LC_977有序数组的平方 {
    public int[] sortedSquares(int[] nums) {
        int[] result=new int[nums.length];
        int k=nums.length-1;
        for(int i=0,j=k;i<=j;){
            if(nums[i]*nums[i]>nums[j]*nums[j]){
                result[k]=nums[i]*nums[i];
                k--;
                i++;
            }
            else {
                result[k]=nums[j]*nums[j];
                k--;
                j--;
            }
        }
        return result;
    }
}
